package com.bbs.service;

import java.util.List;

import com.bbs.dao.ArticleDao;
import com.bbs.dao.ReplyDao;
import com.bbs.entity.Article;
import com.bbs.entity.Reply;
import com.bbs.util.DateUtil;
import com.bbs.util.Page;


public class ArticleService {
	private ArticleDao articleDao = new ArticleDao();
	
	public int save(Article a){
		return articleDao.save(a);
	}

	public Article findById(int id) {
		Article article = articleDao.findById(id);
		List<Reply> list = new ReplyDao().findByAtricleId(article.getId());
		article.setReplyList(list);
		return article;
	}
	
	public List<Article> findByBlocksId(int id) {
		List<Article> list = articleDao.findByBid(id);
		
		return list;
	}

	public int update(Article article) {
		int rows = articleDao.update(article);
		return rows;
	}

	public void deleteById(int id) {
		articleDao.deleteById(id);
	}

	public Article findById(int id, Page page) {
		Article article = articleDao.findById(id);
		List<Reply> list = new ReplyDao().findByAtricleIdAndPage(article.getId(),page);
		article.setReplyList(list);
		return article;
	}

	public int settop(int aid) {
		Article article = articleDao.findById(aid);
		article.setType(2);
		article.setSettoptime(DateUtil.getNow());
		return articleDao.update(article);
	}

	public List<Article> findMineByUid(int id,Page p) {
		return articleDao.findMineByUid(id,p);
	}

	public List<Article> findAnc() {
		
		return articleDao.findAnc();
	}
}
